package inits

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"sync"
	"thread/global"
)

var ctx = context.Background()
var once2 sync.Once

func Redis() {

	once2.Do(func() {
		global.Rdb = redis.NewClient(&redis.Options{
			Addr:     "14.103.142.227:6379",
			Password: "305837761788cb2ae277dccf9e918568", // no password set
			DB:       0,                                  // use default DB
		})

		err := global.Rdb.Set(ctx, "key", "value", 0).Err()
		if err != nil {
			panic(err)
		} else {
			fmt.Println("redis连接成功")
		}
	})

}
